package model

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/sqlc"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ ResultproModel = (*customResultproModel)(nil)

type (
	// ResultproModel is an interface to be customized, add more methods here,
	// and implement the added methods in customResultproModel.
	ResultproModel interface {
		resultproModel
		FindSno(ctx context.Context, sno string) ([]Resultpro, error)
	}

	customResultproModel struct {
		*defaultResultproModel
	}
)

// NewResultproModel returns a model for the database table.
func NewResultproModel(conn sqlx.SqlConn) ResultproModel {
	return &customResultproModel{
		defaultResultproModel: newResultproModel(conn),
	}
}

func (m *defaultResultproModel) FindSno(ctx context.Context, sno string) ([]Resultpro, error) {
	query := fmt.Sprintf("select * from %s where sno = $1 limit 100", m.table)
	var resp []Resultpro
	err := m.conn.QueryRowsCtx(ctx, &resp, query, sno)
	switch err {
	case nil:
		return resp, nil
	case sqlc.ErrNotFound:
		return nil, ErrNotFound
	default:
		return nil, err
	}
}
